import { createRouter, createWebHashHistory, type RouteRecordRaw } from 'vue-router'

export const moduleRoutes: RouteRecordRaw[] = []

const modules = import.meta.glob<true, string, any>('@/views/**/*.routes.ts', { eager: true })

// console.log('modules', modules)

for (const router of Object.values(modules)) {
  moduleRoutes.push(router.default)
}
// console.log(moduleRoutes)
const baseRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/dashboard/workplace'
  },
  {
    path: '/login',
    name: 'LoginView',
    component: () => import('@/views/public/login-view/index.vue'),
    meta: {
      needLogin: false,
      alive: false,
      title: '登录'
    }
  },
  {
    path: '/404',
    name: 'ExceptionPage',
    component: () => import('@/views/public/error-view/404.vue'),
    meta: {
      needLogin: false,
      alive: false,
      title: '404-NotFound'
    }
  },
  {
    path: '/:pathMatch(.*)',
    redirect: '/404'
  }
]

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [...baseRoutes, ...moduleRoutes]
})

export default router
